<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Api_order_m extends FOX_Model
{

	function __construct ()
	{
		parent::__construct();
	}
	
	public function count_shop_orders_count_by_good_id($user_id){
		$this->db->select('order_id');
		$this->db->from('shop_orders');
		$this->db->where('user_id',$user_id);
		$total=$this->db->count_all_results();
		return $total;
	}
	//成功订单
	public function count_shop_orders_count_by_good_id_success($user_id){
		$this->db->select('order_id');
		$this->db->from('shop_orders');
		$this->db->where('user_id',$user_id);
		$this->db->where('order_status',2);
		$total=$this->db->count_all_results();
		return $total;
	}
	
	public function chu_shop_orders_count_by_good_id($good_id){
		$this->db->select_max('order_price');
		$this->db->where('good_id',$good_id);
		$this->db->where('order_status',1);
		$query = $this->db->get('shop_orders');
		return $query->row_array();
	}
	
	public function avg_shop_orders_count_by_good_id($good_id){
		$this->db->select_avg('order_price');
		$this->db->where('good_id',$good_id);
		$this->db->where('order_status',2);
		$query = $this->db->get('shop_orders');
		return $query->row_array();
	}

	public function get_orders_list($page=0,$limit=4,$user_id=0,$ord='desc')
	{
		$start = $page*$limit;
		$query = $this->db->select('*')->from('shop_orders')->where(array('user_id'=>$user_id,'order_status'=>2))->order_by('order_id',$ord)->limit($limit,$start)->get();
		return $query->result_array();
	}

	public function get_footpoint_list($page=0,$limit=6,$user_id=0,$ord='desc')
	{
		$start = $page*$limit;
		$query = $this->db->select('*')->from('user_views')->where('user_id',$user_id)->order_by('view_id',$ord)->limit($limit,$start)->get();
		return $query->result_array();
	}
	public function get_recording_list($page=0,$limit=6,$user_id=0,$ord='desc',$order_status)
	{
		$start = $page*$limit;
		if($order_status){
			$query = $this->db->select('*')->from('shop_orders')->where(array('user_id'=>$user_id,'order_status'=>$order_status))->order_by('order_id',$ord)->limit($limit,$start)->get();
		}else{
			$query = $this->db->select('*')->from('shop_orders')->where('user_id',$user_id)->order_by('order_id',$ord)->limit($limit,$start)->get();
		}
		
		return $query->result_array();
	}
	public function count_user_views_count_by_user_id($user_id){
		$this->db->select('view_id');
		$this->db->from('user_views');
		$this->db->where('user_id',$user_id);
		$total=$this->db->count_all_results();
		return $total;
	}
	public function count_recordings_count_by_user_id($user_id,$order_status){
		if($order_status){
			$this->db->select('order_id');
		$this->db->from('shop_orders');
		$this->db->where(array('user_id'=>$user_id,'order_status'=>$order_status));
	}else{
		$this->db->select('order_id');
		$this->db->from('shop_orders');
		$this->db->where('user_id',$user_id);
	}	
		$total=$this->db->count_all_results();
		return $total;
	}

}
